//: Playground - noun: a place where people can play

import UIKit

//OC中的字符串使用@"",在swift中的字符串使用""
//注意：OC中的字符串是NSString但是在Swift中的字符串是String
/**
 OC中的字符串是NSObject
 Swift中的字符串是结构体
 Swift中的字符串性能比OC更高
 */

//创建字符串
var str = "zhangjian"

//拼接
var str1 = "name"
str += str1

//格式化
let name1 = "tangqian"
let age = 20
let str2 = "name = \(name1),age = \(age)"

//特殊格式拼接
var str3 = String.init(format: "%02d: %02d: %02d", arguments: [1,2,3])

//字符串的截取
//截取"tan"
let index = name1.index(name1.startIndex, offsetBy: 2)
let subStr = name1[...index]

//截取"ngq"
let index1 = name1.index(name1.startIndex, offsetBy: 2)
let index2 = name1.index(index1, offsetBy: 2)
let subStr1 = name1[index1...index2]

//转换成OC方式截取字符串
let str4 = name1 as NSString
let subStr2 = str4.substring(with: NSMakeRange(2, 3))


let name = "Marie Curie"
let firstSpace = name.index(of: " ") ?? name.endIndex
let firstName = name[..<firstSpace]

//Swift中的字符串遍历
var str5 = "www.baidu.com"
for c in Array(str5) {
    print(c)
}

